package IC.Semantics.symbols;

/**
 * extends the block symbol table so we can add blocks anonymously to the table 
 *
 */
public class MethodSymbolTable extends BlockSymbolTable
{
	public static final String THIS_VAR_NAME = "this";
	
	
	public MethodSymbolTable(SymbolTable parent, String name) {
		super(parent);
		this.name = name;
	}
	
	public void insert(String name, SemanticSymbol s){
		entries.put(name, s);
	}
	
	public String dump()
	{
		StringBuilder str = new StringBuilder("Method Symbol Table: "+name);
		
		StringBuilder params = new StringBuilder();
		StringBuilder ret = new StringBuilder();
		for (SemanticSymbol s : entries.values())
		{
			if (s.kind == SemanticKind.PARAM)
				params.append("\n\tParameter: " + s.type.toString() + " " + s.name);
			else if (s.kind == SemanticKind.VARIABLE && !s.getName().equals(THIS_VAR_NAME))
				ret.append("\n\tLocal variable: " + s.type.toString() + " " + s.name);
		}
		
		str.append(params);
		str.append(ret);
		
		if (!children.isEmpty())
		{
			str.append("\nChildren tables: ");
			for (SymbolTable bst : children.values())
				str.append(bst.name + ", ");
			
			str.delete(str.length()-2, str.length());
		}
		
		str.append("\n\n");
		for (SymbolTable bst : children.values())
			str.append(bst.dump());
		
		return str.toString();
	}
	
}
